from django.utils.translation    import ugettext_lazy as _
from sitepal.sitebase.conf       import properties
from sitepal.sitetheme.renderers import BlockRenderer

class BannerBlockRenderer(BlockRenderer):
    def render_content(self,request):
        front_page = properties.get('site-front-page','/',admin=True)
        logo_path  = properties.get('site-logo',admin=True)
        logo       = ''
        site_link  = ''
        if logo_path:
            image = self.render_image(src=logo_path,alt=_("Home"),attributes={'id':'id_logo_image'})
            logo  = self.render_link(content   =image,
                                     url       =front_page,
                                     attributes={'id':'id_logo_link','title':_("Home")})
        if self.site_name():
            site_link = self.render_link(content   =self.site_name(),
                                         url       =front_page,
                                         attributes={'title':_("Home")})
        context = self.user_context(request)
        context.update({
            'logo'     : logo,
            'site_link': site_link,
        })
        return self.render_template('theme/banner.html',context)

class MainContentBlockRenderer(BlockRenderer):
    def render_content(self,request):
        if request and hasattr(request,'main_content'):
            return self.escape(request.main_content)
        return u''

definitions = {
    'banner': {
        'title'          : u"Site Banner",
        'description'    : u"Displays the logo, title and slogan of the site",
        'grid_position'  : 'alpha omega',
        'grid_width'     : 24,
        'display_title'  : False,
        'renderer'       : BannerBlockRenderer,
    },
    'main_content': {
        'title'          : u"Main Page Content",
        'description'    : u"Displays the main content of the page",
        'grid_position'  : 'alpha omega',
        'grid_width'     : 18,
        'display_title'  : False,
        'renderer'       : MainContentBlockRenderer,
    },
}
